package com.mgee.netty.server.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mgee.netty.server.netty.IoSession;
import com.mgee.netty.server.protobuf.ImProto.GameCommand;
import com.mgee.netty.server.protobuf.ImProto.ImMsg;
import lombok.extern.slf4j.Slf4j;

/**
 * 
 * @author mileswan
 *
 */
@Service
@Slf4j
public class CommandService {
	
	@Autowired
	private RoomService roomService;
	
	public void dispatch(ImMsg imMsg, IoSession currSession) {
		
		try {
			GameCommand gameCommand = imMsg.getMsg().unpack(GameCommand.class);
			
			switch(gameCommand.getType()) {
			
				case Update_Room_Maxusers:
					roomService.updateMaxUsers(imMsg, currSession);
					break;
				case Sync_Room_User_Status:
					roomService.syncUsers(imMsg, currSession);
					break;
				default:
				
			}
	        
		}catch(Exception e) {
			log.error("CommandService dispatch时发生异常, ", e);
		}
		
		
	}
	
	
}
